package com.example.demo.controller;

import com.example.base.Result;
import com.example.demo.service.GoodsService;
import com.example.demo.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @Resource
    private OrderService orderService;



    @PostMapping("/buy/{id}")
    public ResponseEntity<Object> buy(@PathVariable int id) throws InterruptedException {

        //return goodsService.processOrder(id);
        goodsService.processOrderAndPay(id,"userId123");
        goodsService.processOrderAndPay(id,"userId456");
        goodsService.processOrderAndPay(id,"userId789");
        return Result.Ok();

    }



    @PostMapping("/seckill/{id}")
    public ResponseEntity<Object> seckill(@PathVariable int id) throws InterruptedException {

        return goodsService.seckill(id);
    }
}
